package com.ys.otms.services.impl;

import com.ys.otms.dao.IConsumeDao;
import com.ys.otms.dto.ConsumeDto;
import com.ys.otms.dto.ParamDto;
import com.ys.otms.services.IConsumeServices;
import com.ys.otms.utils.*;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/10/12.
 */
@Service
public class ConsumeSerivceImpl implements IConsumeServices {
    private static Logger logger = LoggerFactory.getLogger(ConsumeSerivceImpl.class);

    @Autowired
    private IConsumeDao iConsumeDao;
    @Override
    public Map<String,Object> selectConsumeQuery(HttpServletRequest request,ParamDto param) throws Exception {
        logger.info("ConsumeSerivceImpl selectConsumeQuery start obj{}",param);
        Map<String,Object> map = new HashMap<>();
        param.setConsumeStatus(1);
        param.setUserId(Integer.parseInt((String) request.getSession().getAttribute("SESSION_COMPANY_ID")));
        List<ConsumeDto> consumeDtoList = iConsumeDao.selectConsumeQuery(param);
        int consumeCount = iConsumeDao.selectConsumeByCount(param);
        for (int i = 0; i <consumeDtoList.size() ; i++) {
            consumeDtoList.get(i).setConsume_Time(consumeDtoList.get(i).getConsumeTime().toString().substring(0,consumeDtoList.get(i).getConsumeTime().toString().indexOf(".")));
        }
        map.put("data",consumeDtoList);
        map.put("count",consumeCount);
        return  map;
    }

}
